﻿@model List<Core_Product>
@{
    ViewBag.ParentUrl = "/Product/Index";
    ViewBag.Title = "分配产品";
}
@section breadcrumb
{
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="/">控制台</a>
        </li>
        <li class="active">@ViewBag.Title</li>
    </ul><!-- .breadcrumb -->
}
<div class="row">
    <div class="col-xs-12">
        <div class="table-responsive">

            <h4 class="pink">
                <i class="ace-icon fa fa-user icon-animated-hand-pointer blue"></i>
                <a href="###" role="button" class="green" data-toggle="modal">@ViewBag.UserName</a>
            </h4>
            <div class="hr hr-18 dotted hr-double"></div>
            <div class="nav-search" id="nav-search" style="top: 6px;">

                <button class="btn btn-success btn-xs" id="btnAllot">
                    <i class="ace-icon fa fa-save bigger-110"></i>
                    确认分配
                </button>
            </div><!-- #nav-search -->
            <!-- PAGE CONTENT BEGINS -->
            <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>
                            <label class="position-relative">
                                <input type="checkbox" class="ace" id="chkAll" />
                                <span class="lbl"></span>
                            </label>
                        </th>
                        <th>产品名称</th>
                        <th>产品代码</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {

                        <tr>
                            <td>
                                <label class="position-relative">
                                    <input type="checkbox" class="ace" value="@item.P_Id" name="chkItem" @{
                                                                                          if (item.P_Flag == 1)
                                                                                          {
                                                                                                @:checked="checked"                                                                                                            
                                                                                          }
                                                                                      } />
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>
                                @item.P_Name @item.P_Flag
                            </td>
                            <td>@item.P_Code</td>
                        </tr>

                    }
                </tbody>
            </table>
        </div> <!-- PAGE CONTENT ENDS -->
    </div><!-- /.col -->
</div><!-- /.row -->
@section footer{
    <script>
        $(function() {

            /**
            * 全选/反选
            **/
            $('#chkAll').click(function() {
                var state = $(this).prop('checked');
                $('input[name="chkItem"]').prop('checked', state);
            });
            /**
            分配
            */
            $('#btnAllot').click(function() {
                var chkIds = '';
                $.each($('input[name="chkItem"]:checkbox:checked'), function() {
                    chkIds = $(this).val() + ',';
                });
                if (chkIds == '') {
                    alert('没有选择数据');
                    return false;
                }
                $.post("/product/allot", { uid: @ViewBag.UserId, ids: chkIds }, function(o) {
                    alert(o);
//                    if (o == 'ok') {
//                        alert('分配成功');
//                    } else {
//                        alert('分配失败');
//                    }
                    console.log();
                });
            });

        });
    </script>
}